<!--散点图-->
<template>
  <div class="chartcontainer" v-if="iffresh">
    <div :style="{'margin-bottom':'10px'}"  v-if="title">{{title}}</div>
    <!-- :judge-width="true" -->
    <ve-scatter
      :data="blockdata"
      width="100%"
      height="100%"
      ref="mychart"
      :theme="theme"
      :judge-width="true"
      :after-config="afterConfig"
      :grid="grid"
    ></ve-scatter>
  </div>
</template>

<script>
import VeScatter from "v-charts/lib/scatter.common";

export default {
  props: {
    chartData: [Object],
    changesizewidth: [Number, String],
    changesizeheight: [Number, String],
    timer: [Number, String],
    theme: [Object],
    title: [String],
    searchid: [Number, String],
    chartid: [Number, String],
    field: [String],
    isShowLegend: {
      type: Boolean,
      default: true
    }
  },
  data() {
    this.chartSettings = {};

    this.grid = {
      left: 30,
      top: 40,
      right: 60,
      bottom: 60
    };
    return {
      intervaltime: this.timer,
      blockdata: this.chartData,
      iffresh: true
    };
  },

  components: { VeScatter },
  created() {},
  mounted() {},
  destroyed() {},
  methods: {
    afterConfig(options) {
      if (!this.isShowLegend) {
        options.legend = {
          data: []
        };
      }
      options.xAxis[0].axisLabel = {
        interval: 0,
        textStyle: {
          fontSize: 10 //刻度大小
        },
        formatter: function(val) {
          if (val.length < 10) {
            return val.split("").join("\n");
          }
          var strs = val.split(""); //字符串数组
          var str = "";
          for (var i = 0, s; (s = strs[i++]); ) {
            //遍历字符串数组
            str += s;
            if (!(i % 2)) str += "\n"; //按需要求余
          }
          return str;
        } //横轴
      };
      return options;
    }
  },
  watch: {
    changesizewidth(oldvalue, newvalue) {
      this.$refs.mychart.echarts.resize();
    },

    changesizeheight(oldvalue, newvalue) {
      this.$refs.mychart.echarts.resize();
    },
    chartData(oldvalue, newvalue) {
      this.blockdata = oldvalue;
    }
  }
};
</script>
<style scoped lang="scss">
.chartcontainer {
  width: 100%;
  height: 100%;
}
</style>

